
%**************************************************************************
%
%           "Endogenous Liquidity and Capital Reallocation"
%      Cui, W., Wright, R., & Zhu, Y. (2024), Journal of Political Economy
%                       Last Modified: Feb 2024.  
%
%**************************************************************************


%%%% This code produces long-run comparison in scatter plots (data v.s. model)
clear; clc; close all


%% Step 1: Load model and data
load param_calibrated
par = par_calibrated;

load model_long_run_raw
load('../data/variables.mat')

inflation_trend     = variables_trend(:,1);
ItoOutput_trend     = variables_trend(:,2);
CtoOutput_trend     = variables_trend(:,3);
R_share_trend       = variables_trend(:,4);
P_share_trend       = variables_trend(:,5);

%inflation_trend_model = Table_model{2}(:,1) - 1/par.BETA + 1;
inflation_trend_model = log (1 + Table_model{2}(:,1)) - log(1 / par.BETA);
pi_min = 0.01;
pi_max = 0.1;

%% Step 2: Plot figures
%%%% The following controls which THETA to be used; 
%%%% We calibrated for different THETAs; {2} means the middle and the calibrated one

data_vs_model_long_run = figure;

subplot(2,2,1)
title('Investment/(Private) Output')
hold on
plot(inflation_trend_model, Table_model{2}(:,2), 'red', 'linewidth', 2)
scatter(inflation_trend, ItoOutput_trend, 15,'filled','blue')
xlim([pi_min, pi_max])
xlabel('$\pi$', 'interpreter', 'latex')

subplot(2,2,2)
title('Consumption/(Private) Output')
hold on
plot(inflation_trend_model, Table_model{2}(:,3), 'red', 'linewidth', 2)
scatter(inflation_trend, CtoOutput_trend, 15,'filled','blue')
xlim([pi_min, pi_max])
xlabel('$\pi$','interpreter','latex')


subplot(2,2,3)
title('R Share')
hold on
plot(inflation_trend_model, Table_model{2}(:,5), 'red','linewidth', 2)
scatter(inflation_trend, exp(R_share_trend), 15,'filled','blue')
xlim([pi_min, pi_max])
xlabel('$\pi$','interpreter','latex')

subplot(2,2,4)
title('P Share')
hold on
plot(inflation_trend_model, Table_model{2}(:,6), 'red', 'linewidth', 2)
scatter(inflation_trend, exp(P_share_trend), 15,'filled','blue')
xlim([pi_min, pi_max])
xlabel('$\pi$','interpreter','latex')

saveas(data_vs_model_long_run, 'figures/data_model_lr','epsc')
saveas(data_vs_model_long_run, 'figures/data_model_lr','png')

